/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package negocio;

import java.sql.*;


/**
 *
 * @author Administrador
 */
public class integrante {
    private int id_int;
    private String nombre_int;
    private String apellido_int;
    private String user_int;
    private String password_int;
    private String rol_int;

    public integrante() {
    }

    public integrante(String nombre_int, String apellido_int, String user_int, String password_int, String rol_int) {
        this.nombre_int = nombre_int;
        this.apellido_int = apellido_int;
        this.user_int = user_int;
        this.password_int = password_int;
        this.rol_int = rol_int;
    }


    public String getApellido_int() {
        return apellido_int;
    }

    public void setApellido_int(String apellido_int) {
        this.apellido_int = apellido_int;
    }

    public int getId_int() {
        return id_int;
    }

    public void setId_int(int id_int) {
        this.id_int = id_int;
    }

    public String getNombre_int() {
        return nombre_int;
    }

    public void setNombre_int(String nombre_int) {
        this.nombre_int = nombre_int;
    }

    public String getPassword_int() {
        return password_int;
    }

    public void setPassword_int(String password_int) {
        this.password_int = password_int;
    }

    public String getRol_int() {
        return rol_int;
    }

    public void setRol_int(String rol_int) {
        this.rol_int = rol_int;
    }

    public String getUser_int() {
        return user_int;
    }

    public void setUser_int(String user_int) {
        this.user_int = user_int;
    }
    

    /**************************************
     * Método: existeUsuario
     * Determina si el usuario que ingresa
     * al sistema, existe o no, validando
     * el user y password
    ***************************************/
    public boolean existeUsuario(String usu,String pass, String url){
        ManejadorBaseDato c = new ManejadorBaseDato();
        try {
            Connection conn;
            Statement st;
            PreparedStatement ps;
            ResultSet rs;
            
            c.RealizarConexion(url);
            conn = c.getCon();
            st = conn.createStatement();
            rs = st.executeQuery("SELECT * FROM integrantes WHERE user='"+usu+"' AND password='"+pass+"'");
             // rset.next();
            if ( rs.next()){
                String usuarioBase = rs.getString("user");          
                String passwordBase = rs.getString("password");
                //System.out.println(passwordBase);
                rs.close();
                if ( usuarioBase.equals(usu) && passwordBase.equals(pass) ){
                   //System.out.println("gg");
                    this.user_int=usu;
                    this.password_int=pass;

                    //System.out.println(password_int);
                    return true;
                } 
            }
        }catch (SQLException ex) {
           ex.printStackTrace();
        }
        try{
            c.CerrarConexion();
        }
        catch(Exception e){}
        return false;
    }



/**************************************
 * Método: obtenerIdentidad
 * Devuelve el nombre y el apellido
 * del usuario que ingreso al sistema
***************************************/

    public String obtenerIdentidad(String url){
        ManejadorBaseDato c = new ManejadorBaseDato();
        try {
            Connection conn;
            Statement st;
            PreparedStatement ps;
            ResultSet rs;

            c.RealizarConexion(url);
            conn = c.getCon();
            st = conn.createStatement();
            rs = st.executeQuery("SELECT * FROM integrantes where user='"+user_int+"' AND password='"+password_int+"'");
             // rset.next();
            if ( rs.next()){
                this.nombre_int = rs.getString("nombre");
                this.apellido_int = rs.getString("apellido");
                rs.close();

                return nombre_int+" "+apellido_int;
            }
        }catch (SQLException ex) {
           ex.printStackTrace();
        }
        try{
            c.CerrarConexion();
        }
        catch(Exception e){}
        return "";
    }


 /**************************************
 * Método: obtenerRol
 * Devuelve el rol del usuario
 * que ingreso al sistema
 ***************************************/

    public String obtenerRol(String url){
        ManejadorBaseDato c = new ManejadorBaseDato();
        try {
            Connection conn;
            Statement st;
            PreparedStatement ps;
            ResultSet rs;

            c.RealizarConexion(url);
            conn = c.getCon();
            st = conn.createStatement();
            rs = st.executeQuery("SELECT * FROM integrantes where user='"+user_int+"' AND password='"+password_int+"'");
             // rset.next();
            if ( rs.next()){
                this.rol_int= rs.getString("rol");
                this.nombre_int= rs.getString("nombre");
                rs.close();


                return rol_int;
            }
        }catch (SQLException ex) {
           ex.printStackTrace();
        }
        try{
            c.CerrarConexion();
        }
        catch(Exception e){}
        return "";
    }




}

